package logic

import (
	"context"
	"srv/pb/realname"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealnameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealnameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealnameLogic {
	return &RealnameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealnameLogic) Realname(req *types.RealnameRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	userid := 1
	response, err := l.svcCtx.Srv.Realname(l.ctx, &realname.RealnameRequest{
		Userid:   int64(userid),
		Realname: req.Realname,
		IdCard:   req.IdCard,
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  "实名失败",
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "实名成功",
		Data: map[string]interface{}{
			"response": response,
		},
	}, nil
}
